import { Button, Form, Input, Select,message } from 'antd';
import React from 'react';
import MyEditor from './MyEditor';
import { inject, observer } from 'mobx-react';
import './../../assets/css/knowledge/AddInfor.css'


// 文件上传
// const props = {
//   name: 'file',
//   action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
//   headers: {
//     authorization: 'authorization-text',
//   },

//   onChange(info) {
//       if (info.file.status !== 'uploading') {
//         console.log(info.file, info.fileList);
//       }

//       if (info.file.status === 'done') {
//         message.success(`${info.file.name} 文件上传成功`);
//       } else if (info.file.status === 'error') {
//         message.error(`${info.file.name} 文件上传失败.`);
//       }
//   },
// };

const App = (props) => {
  const { Option } = Select;
  const layout = {
    labelCol: {
      span: 7,
    },
    wrapperCol: {
      span: 5,
    },
  };
  const tailLayout = {
    wrapperCol: {
      offset: 12,
      span: 8,
    },
  };
  const [form] = Form.useForm();

  // const onFill = () => {
  //   form.setFieldsValue({
  //     note: 'Hello world!',
  //   });
  // };
  const onFinish = (values) => {
    props.knowledgeStore.format()
    console.log(values)
    props.knowledgeStore.addListData({ currentPage: 1, pageSize: 20, sort: values.sort, title: values.title, outline: props.knowledgeStore.addInfo.outline, user_name: '超级管理员' }).then(() => {
      props.knowledgeStore.getAllListData({ currentPage: 1, pageSize: 20 })
    })
  };

  const onReset = () => {
    form.resetFields();
  };
 
 
 

  return (
    <Form {...layout} form={form} name="data" onFinish={onFinish} spellCheck='false' id='KnowledgeAddInfo'>
      <Form.Item
        name="sort"
        label="知识库分类"
        wrapperCol={{ span: 2 }}
        rules={[
          {
            required: true,
          },
        ]}
      >
        <Select
          placeholder="请选择"
        >
          <Option value="xiaoshou">销售话术</Option>
          <Option value="hangye">行业分析</Option>
        </Select>
      </Form.Item>
      <Form.Item
        name="title"
        label="知识库标题"
        rules={[
          {
            required: true,
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        name="outline"
        label="知识库内容"
        wrapperCol={{ span: 12 }}
      >
        <MyEditor />
      </Form.Item>
      {/* <Form.Item
        label="附件"
        wrapperCol={{ span: 10 }}
      >
        <Upload {...props}>
          <Button className='uploadBtn'>选择文件</Button>
        </Upload>
      </Form.Item> */}
      
      <Form.Item {...tailLayout}>
        <Button type="primary" htmlType="submit">
          保存
        </Button>
        <Button htmlType="button" onClick={onReset}>
          关闭
        </Button>
      </Form.Item>
    </Form>
  );
};

export default inject('knowledgeStore')(observer(App))

